"""
    Author: Huang liuchao
    Contact: huanglc50@chinaunicom.cn
    Datetime: 2020/10/29 9:48
    Software: PyCharm
    File description：
        
"""
import os
import os.path
import pandas as pd
import numpy as np
import xlwt
import xlrd
from xlutils.copy import copy
from datetime import date,datetime
def merage_data(dir_path,to_file_path,get_head_file_path):
    df1 = pd.read_excel(get_head_file_path)
    # print(df1.columns.tolist())
    head_list = df1.columns.tolist()
    value_list = []
    df = pd.DataFrame(dict(zip(head_list, value_list)))
    # print(df)
    print('正在合并文件.........')
    for filename in os.listdir(dir_path):
        filename = dir_path + "/" + filename
        data = pd.read_excel(filename)
        # print(data)
        df = pd.concat([df, data])
        # print(df)
    df.to_excel(to_file_path, encoding='utf-8', index=None)
    print('文件合并完成！！')
if __name__ == '__main__':
    abspath = os.path.abspath('../../../data')  # 设置相对路径（基准路径）
    dir_path = abspath + r'\onenet_warning_data1'
    # dir_path = r'./onenet_warning_data1'
    md_dir = r'get_onenet_unique_warning'
    md_dir_path = os.path.join(dir_path, md_dir)
    to_file_name = to_file_name = r'unique_onenet_warning_detail.xlsx'
    md_to_file_path = os.path.join(dir_path, to_file_name)
    file_list = os.listdir(md_dir_path)
    head_file_name = file_list[0]
    md_head_file_path = os.path.join(md_dir_path, head_file_name)

    merage_data(md_dir_path, md_to_file_path, md_head_file_path)